# import time
#
#
# # start_time = time.time()
# # for a in range(0, 1001):
# #     for b in range(0, 1001):
# #         for c in range(0, 1001):
# #             if a + b + c == 1000 and a ** 2 + b ** 2 == c ** 2:
# #                 print("a, b, c:%d, %d, %d" % (a, b, c))
#
# start_time = time.time()
# for a in range(0, 1001):
#     for b in range(0, 1001):
#         c = 1000 - a - b
#         if a**2 + b**2 == c**2:
#             print("a, b, c:%d, %d, %d" % (a, b, c))
#
# end_time = time.time()
# print("times:%d" % (end_time-start_time))
# print("finished")

from timeit import Timer

def test1():
    li = []
    for i in range(10000):
        # li += [i]  不完全等于以下语句, 有优化
        li = li + [i]

def test2():
    li = []
    for i in range(10000):
        li.append(i)

def test3():
    li = [i for i in range(10000)]

def test4():
    li = list(range(10000))

def test5():
    li = []
    for i in range(10000):
        li.extend([i])

def test6():
    li = []
    for i in range(10000):
        li.insert(0, i)

# timer1 = Timer("test1()", "from __main__ import test1")
# print("+:", timer1.timeit(number=1000))
#
# timer2 = Timer("test2()", "from __main__ import test2")
# print("append:", timer2.timeit(number=1000))
#
# timer3 = Timer("test3()", "from __main__ import test3")
# print("构造器:", timer3.timeit(number=1000))
#
# timer4 = Timer("test4()", "from __main__ import test4")
# print("类型转换:", timer4.timeit(number=1000))
#
# timer5 = Timer("test5()", "from __main__ import test5")
# print("extend:", timer5.timeit(number=1000))
#
# timer6 = Timer("test6()", "from __main__ import test6")
# print("insert:", timer6.timeit(number=1000))
